package com.github.ghsea.cc.runner;

import java.util.concurrent.TimeUnit;

import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.topology.TopologyBuilder;
import org.apache.storm.tuple.Fields;

import com.github.ghsea.cc.bolt.CounterByIpBolt;
import com.github.ghsea.cc.bolt.NginxLogSplitBolt;
import com.github.ghsea.cc.consts.FiledName;
import com.github.ghsea.cc.spout.LocalFileSpout;

public class LocalCCAntiRunner {

	/**
	 * @param args
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws InterruptedException {
		LocalCluster local = null;
		try {
			local = new LocalCluster();

			TopologyBuilder tb = new TopologyBuilder();
			tb.setSpout("LocalFileSpout", new LocalFileSpout(), 1);

			tb.setBolt("NginxLogSplitBolt", new NginxLogSplitBolt(),3).shuffleGrouping("LocalFileSpout");
			tb.setBolt("CounterByIpBolt", new CounterByIpBolt(),3).fieldsGrouping("NginxLogSplitBolt",
					new Fields(FiledName.ACCESS_IP));

			Config config = new Config();
			config.setDebug(false);
			local.submitTopology("CC-Anti", config, tb.createTopology());
			TimeUnit.MINUTES.sleep(5);
			local.shutdown();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (local != null) {
				local.shutdown();
			}
		}
	}

}
